package com.ruoyi.assets.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.assets.mapper.AssetCategoriesMapper;
import com.ruoyi.assets.domain.AssetCategories;
import com.ruoyi.assets.service.IAssetCategoriesService;

/**
 * 资产类别Service业务层处理
 * 
 * @author sfk
 * @date 2025-03-03
 */
@Service
public class AssetCategoriesServiceImpl implements IAssetCategoriesService 
{
    @Autowired
    private AssetCategoriesMapper assetCategoriesMapper;

    /**
     * 查询资产类别
     * 
     * @param categoryId 资产类别主键
     * @return 资产类别
     */
    @Override
    public AssetCategories selectAssetCategoriesByCategoryId(Long categoryId)
    {
        return assetCategoriesMapper.selectAssetCategoriesByCategoryId(categoryId);
    }

    /**
     * 查询资产类别列表
     * 
     * @param assetCategories 资产类别
     * @return 资产类别
     */
    @Override
    public List<AssetCategories> selectAssetCategoriesList(AssetCategories assetCategories)
    {
        return assetCategoriesMapper.selectAssetCategoriesList(assetCategories);
    }

    /**
     * 新增资产类别
     * 
     * @param assetCategories 资产类别
     * @return 结果
     */
    @Override
    public int insertAssetCategories(AssetCategories assetCategories)
    {
        return assetCategoriesMapper.insertAssetCategories(assetCategories);
    }

    /**
     * 修改资产类别
     * 
     * @param assetCategories 资产类别
     * @return 结果
     */
    @Override
    public int updateAssetCategories(AssetCategories assetCategories)
    {
        return assetCategoriesMapper.updateAssetCategories(assetCategories);
    }

    /**
     * 批量删除资产类别
     * 
     * @param categoryIds 需要删除的资产类别主键
     * @return 结果
     */
    @Override
    public int deleteAssetCategoriesByCategoryIds(Long[] categoryIds)
    {
        if (categoryIds == null || categoryIds.length == 0) {
            throw new IllegalArgumentException("传入的 categoryIds 数组不能为空");
        }
        AssetCategories assetCategories = new AssetCategories();
        if(assetCategories.getStatus().equals("1")){
            throw new RuntimeException("当前所选项为启用状态，请先禁用当前所选项，再删除");
        }else {
            return assetCategoriesMapper.deleteAssetCategoriesByCategoryIds(categoryIds);
        }
    }

    /**
     * 删除资产类别信息
     * 
     * @param categoryId 资产类别主键
     * @return 结果
     */
    @Override
    public int deleteAssetCategoriesByCategoryId(Long categoryId)
    {
        AssetCategories assetCategories = new AssetCategories();
        if(assetCategories.getStatus().equals("1")) {
            throw new RuntimeException("当前所选项为启用状态，请先禁用当前所选项，再删除");
        }else {
            return assetCategoriesMapper.deleteAssetCategoriesByCategoryId(categoryId);
        }
    }

    /**
     * 启用状态
     * @param categoryIds
     * @return
     */
    @Override
    public int startStatusAssets(Long[] categoryIds) {
        if (categoryIds == null || categoryIds.length == 0) {
            throw new IllegalArgumentException("传入的 categoryIds 数组不能为空");
        }
        for (Long categoryId : categoryIds) {
            AssetCategories assetCategories = assetCategoriesMapper.selectAssetCategoriesByCategoryId(categoryId);
            // 判断是否为空，是否为启用状态
            if (assetCategories == null || "1".equals(assetCategories.getStatus())) {
                throw new RuntimeException("请选择禁用状态项，进行操作");
            }
        }
            return assetCategoriesMapper.startStatusAssets(categoryIds);
    }

    /**
     * 禁用状态
     * @param categoryIds
     * @return
     */
    @Override
    public int endStatusAssets(Long[] categoryIds) {
        if (categoryIds == null || categoryIds.length == 0) {
            throw new IllegalArgumentException("传入的 categoryIds 数组不能为空");
        }
        for (Long categoryId : categoryIds) {
            AssetCategories assetCategories = assetCategoriesMapper.selectAssetCategoriesByCategoryId(categoryId);
            if (assetCategories == null || !"1".equals(assetCategories.getStatus())) {
                // 判断是否为空，是否为禁用状态
                throw new RuntimeException("请选择启用状态项，进行操作");
            }
        }
            return assetCategoriesMapper.endStatusAssets(categoryIds);
    }
}
